﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>关键词回复设置</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script> 
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
	<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
<script type="text/javascript" src="../js/checkLogin.js"></script> 
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script charset="utf-8" src="../js/lang/zh_CN.js"></script>
	<script charset="utf-8" src="../js/editor2.js"></script>
	<script charset="utf-8" src="../js/find.js"></script>
	<script type="text/javascript" src="../js/pagination.js"></script>
	<script charset="utf-8" src="../js/keyWordReplySelecterNew.js"></script>
	<link rel="stylesheet" href="../css/default.css" />
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
$(function(){
	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	$('.doubledate').kuiDate({
		className:'doubledate',
		isDisabled: "1"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
	restForm();
	
});

var pageCount=0;
var pageIndex=1;
$(function(){

	$(".hideDiv").each(function(){
		addMargin($(this));
	})
	
});





function getFucnMenuDetailList(page){
	if(IsEmpty(page)){
		page=1
	}
	var keyId2=$("#keyId2").val();
	var status=$("#status").val();
	var key=$("#key").val();	
	if(IsEmpty(keyId2)){
		keyId2='';
	}
	
	param={'key':key,'title':keyId2,'status':status}

	
	 adList = _findInfo("../keyWord/find/keyWordList/"+(page -1)+"/10", param);
	if(adList.state==0){
		 var pTr = new Array("keyWord","title","content","imageUrl","url","staName");
		 _loadInfoOfUpdateAndDelete(adList, "funcMenuList", "updateAd", "popPoint", pTr, "id")
		 _loadPage("pager", page, 10, adList, getFucnMenuDetailList, "NoResult")
		$("#sup").html("共"+adList.result.len+"条");	
		 $("#funcMenuList tbody tr").each(function(){
			 var imgTD= $(this).children("td").eq(3).html()
			 var urlTD= $(this).children("td").eq(4).html()
			 if(IsNotEmpty(imgTD)){
				 
			 var imagUrl= "<img src='"+ imgTD+"'/>";
			 }
			 $(this).children("td").eq(3).html(imagUrl)

			 if(IsNotEmpty(urlTD)){
				 var url= "<a href='"+ urlTD+"' target=\"_blank\">查看</a>";
				 }
			 $(this).children("td").eq(4).html(url)
			 
		 })
		 
	}
	
}



function toAdd(){
	
	restForm();
	
	$("#doflag").val(1);
	$("#save_btn").val("立即提交");
	$("#yinying1,#mainMenu").show();
	
}

function updateAd(id){
	restForm()
	for ( var i = 0; i < adList.result.data.length; i++) {
	var ids= getHeadIndexValue(i, adList, "id");
	if(ids==id){
		
	
	var keyWord=getHeadIndexValue(i, adList, "keyWord");
	var shopName=getHeadIndexValue(i, adList, "title");
	var replyId=getHeadIndexValue(i, adList, "replyId");
	var Status=getHeadIndexValue(i, adList, "status");
	var title=getHeadIndexValue(i, adList, "title");
	
	}
	}
	$("#doflag").val(2)
	$("#updateId").val(id);
	 $("#keyWord").val(keyWord)
	$("#Status").val(Status);
	$("#keyWord").val(keyWord)
	if(IsNotEmpty(replyId)){
		var htm = "<option value='"+replyId+"'>"+title+"</option>"
		$("#parentId2").html(htm)
	}	 
	$("#save_btn").val("保存修改")
			$("#yinying1,#mainMenu").show();
}

function save(){
	var doflag=$("#doflag").val();
	if(doflag==1){
		addInfo();
	}else if(doflag==2){
		updateInfo();
	}else{
		art.dialog({fixed:true, lock: true,content:"页面出错",icon:'error',ok:true});	
		getFucnMenuDetailList();
	}
}

function addInfo(){
	var keyWord=$("#keyWord").val()
	var parentId = $("#parentId2").val()
	var status = $("#Status").val()
	if(IsEmpty(parentId)){
		art.dialog({fixed:true, lock: true,content:"请选择对应回复消息",icon:'error',ok:true});
	}
	if(IsEmpty(keyWord)){
		art.dialog({fixed:true, lock: true,content:"关键词不能为空",icon:'error',ok:true});
		$("#keyWord").focus();
		return false;
	}else{
		if(keyWord.length>50){
			art.dialog({fixed:true, lock: true,content:"关键词过长(50字以内)",icon:'error',ok:true});
			$("#keyWord").focus();
			return false;	
		}
	}
	
	var heads=new Array("replyId","keyWord","status");
	var datas=new Array(parentId,keyWord,status);
	
	
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "add" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	 $("#save_btn").attr("disabled",true)
	$.post("../keyWord/insert",{"data":jsonParserStr}, function(data) {
		 $("#save_btn").attr("disabled",false)
		var dt = JSON.parse(data);
			
				 if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"添加出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					art.dialog({fixed:true, lock: true,content:"添加成功",icon:'succeed',ok:true});
					$("#yinying1,#mainMenu").hide();
					getFucnMenuDetailList(1)
				}else if(dt.state==1){
					art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		
	});
}


function updateInfo(){
	var id=$("#updateId").val()
	if(IsEmpty(id)){
		art.dialog({fixed:true, lock: true,content:"页面出错",icon:'error',ok:true});
		getFucnMenuDetailList();
		return false
	}

	var keyWord=$("#keyWord").val()
	var parentId = $("#parentId2").val()
	var status = $("#Status").val()
	if(IsEmpty(parentId)){
		art.dialog({fixed:true, lock: true,content:"请选择对应回复消息",icon:'error',ok:true});
	}
	if(IsEmpty(keyWord)){
		art.dialog({fixed:true, lock: true,content:"关键词不能为空",icon:'error',ok:true});
		$("#keyWord").focus();
		return false;
	}else{
		if(keyWord.length>50){
			art.dialog({fixed:true, lock: true,content:"关键词过长(50字以内)",icon:'error',ok:true});
			$("#keyWord").focus();
			return false;	
		}
	}
	
	var heads=new Array("replyId","keyWord","status","id");
	var datas=new Array(parentId,keyWord,status,id);
	var parser = new Object();
	var jsonParserStr = null;
	if (IsNotEmpty(datas)){
		addToParser(heads, datas, "edit" , parser);
		jsonParserStr =  JSON.stringify(parser);
	}
	 $("#save_btn").attr("disabled",true);
	 
	 
	$.post("../keyWord/edit",{"data":jsonParserStr}, function(data) {
		 $("#save_btn").attr("disabled",false)
		var dt = JSON.parse(data);	
		 if(IsEmpty(dt)){
				art.dialog({fixed:true, lock: true,content:"修改出错",icon:'error',ok:true});	
				return false;
				}
				if(dt.state==0){
					art.dialog({fixed:true, lock: true,content:"修改成功",icon:'succeed',ok:true});
					$("#yinying1,#mainMenu").hide();
					getFucnMenuDetailList()
					 }else if(dt.state==1){
				art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		
	});
	
}

function deleteInfo(id){

	$.post("../keyWord/del",{"id":id}, function(data) {
		var dt = JSON.parse(data);
		if(IsEmpty(dt)){
			art.dialog({fixed:true, lock: true,content:"删除出错",icon:'error',ok:true});	
			return false;
			}
			if(dt.state==0){
				getFucnMenuDetailList();
				 }else if(dt.state==1){
			art.dialog({fixed:true, lock: true,content:dt.msg,icon:'error',ok:true});
			}else{
				checkStateShowErrorMsgAndDealResult(data);
			}
	});
}


	
	function restForm(){
		 $(".reset").val("");
 		 $("#doflag").val(1)
 		 $("#save_btn").val("立即发布")
 		 $("#save_btn").attr("disabled",false)
 		 $("#parentId2").html("")
		}
	
	
	function popPoint(id){
		art.dialog({fixed:true, lock: true,content:"确认删除该条数据？",icon:'question',ok: function(){ deleteInfo(id)},cancel:true});
		}
	

</script>


</head>

<body>
<!-- InstanceBeginEditable name="EditRegion3" --> 
<div id="yinying"></div>
<div id="yinying1"></div>

<script type="text/javascript">
$(function(){
	refreshInput($(".serWrapper"));
		$(this).prev().prev().val($(this).val())
	})

</script>
<div class="member_search publish WX hideDiv" id='mainMenu'>
<div class="closeTop"><span onclick="closeParent($(this))" class="closeThe"><img src="../images/close.png"></span></div>
       <form name="fm1" action="#" target="post">
       	<input type="hidden" id="updateId">
       	<input type="hidden" id="doflag" value="1">

    <p><span>关键词：</span>
      <input type="text" id="keyWord" class="reset">
    </p>
     <p> <span>回复消息：</span>
        <select id="parentId2"  onclick="openKeyWordReplyListPanel('parentId2')"  ></select>
     </p>   
   
    	<p><span>状态：</span>
   		<select id="Status"><option value="0">使用</option><option value="1">停用</option></select>
    </p>
      <div class="BottomBtn">
        <input type="button"  value="立即提交" onclick="save()" id="save_btn">
      </div>
        </form>      
       </div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">自动回复设置</div>
    <div class="member_search">
      <p>
        <span>关键词：</span>
        <input type="text" id="key" class="absoluteTxt" >
        <span>消息选择：</span>
        <input type="text" id="keyId2" class="absoluteTxt" >
         <input class="btn" id="research" name="查询" type="button" value="查询" onClick="getFucnMenuDetailList(1)" ></p>
        
      </div>
       <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="funcMenuList">
    	<caption><strong>自动回复列表       <span id="sup">共0条</span>  </strong><input type="button" class="common_btn" value="增加" onclick="toAdd()"></caption>
    	<thead>
    	<tr>
    		<th >关键词</th>
        	<th >回复消息标题</th>
        	<th >回复消息内容</th>
    		<th >回复消息图片</th>
    		<th >回复消息内容</th>
        	<th >状态</th>
        	<th >操作</th>
        </tr>
        </thead>
       	<tbody>
       		
       	</tbody>
    </table>
      <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(5,3);
</script>
</body>
<!-- InstanceEnd -->
</html>
